package control;

import java.sql.*;

public class DatabaseConnector {

	private Connection _con;
	private Statement _stmt;
	private ResultSet _rslt;

	public DatabaseConnector() {
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException cnfe) {
			cnfe.printStackTrace();
			System.exit(0);
		}
		getConnection();
	}

	private void getConnection() {
		try {
			_con = DriverManager.getConnection(
					"jdbc:mysql://localhost/minesweeper", "mine_admin",
					"starbie9");
			getResult(_con);
		} catch (SQLException sqle) {
			sqle.printStackTrace();
			System.exit(0);
		}
	}

	private void getResult(Connection connection) {
		try {
			_stmt = connection.createStatement();
			_rslt = _stmt.executeQuery("select * from tbl_benutzer");
			while(_rslt.next()){
				System.out.println("Username :" + _rslt.getString(1));
				System.out.println("Vorname  :" + _rslt.getString(2));
				System.out.println("Nachname :" + _rslt.getString(3));
				System.out.println("Passwort :" + _rslt.getString(4));
				System.out.println("Email    :" + _rslt.getString(5));
				System.out.println("-----------------------------------------");
			}
		} catch (SQLException e) {
			e.printStackTrace();
			System.exit(0);
		}
	}
	
	public static void main(String[] args) {
		new DatabaseConnector();
	}

}
